package linkList;

public class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public static void printList(ListNode head) {
        ListNode p = head;
        while (p != null) {
            System.out.print(p.val + "\t");
            p = p.next;
        }
        System.out.println();
    }

    public static ListNode generaListByArray(int[] arr) {
        ListNode virtualHead = new ListNode();
        ListNode temp = virtualHead;
        for (int i : arr) {
            temp.next = new ListNode(i);
            temp = temp.next;
        }
        return virtualHead.next;
    }
}
